package com.itheima.tliassystem.controller;


import com.itheima.tliassystem.aspect.Log;
import com.itheima.tliassystem.aspect.OperateLog;

import com.itheima.tliassystem.service.DepService;
import entity.Dept;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.util.List;
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    DepService depService;

    @GetMapping
    @OperateLog
    public Result list(){
        List<Dept> deptList = depService.listDept();
        return Result.success(deptList);

    }@PostMapping
    @Log
    @OperateLog
    public Result add(@RequestBody Dept dept){
        depService.addDept(dept);
        return Result.success();
    }
    //ID删除  哈哈哈
    @DeleteMapping("{id}")
    @Log
    @OperateLog
    public Result delete(@PathVariable Integer id) throws FileNotFoundException {
        depService.remove(id);
        return Result.success();
   }
   @PutMapping
    public Result  update(@RequestBody Dept dept){
        depService.update(dept);
        return Result.success();
    }
    @GetMapping("{id}")
    @OperateLog
    public Result select(@PathVariable Integer id){
        Dept dept = depService.selectById(id);
        return Result.success(dept);
    }
}
